﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using cancerportal.Entitys;
using cancerportal.Procedure;

namespace cancerportal.Models
{
    public class AskSymptomModels 
    {
        public List<disease> listDisease { get; set; }
        public List<symptomEntity> allSymptom { get; set; }
        public float range = 0.2f; // set range 

        public void listRank(String listSymptom)
        {
            String xmlListDisease = "<Disease>";
            DiseaseProcedure proc = new DiseaseProcedure();
            this.listDisease = new List<disease>(proc.getDiseaseWithWeight(listSymptom, range)); //return list disease from procedure
            foreach(disease obj in this.listDisease){
                xmlListDisease += "<id>"+ obj.id +"</id>";
            }
            xmlListDisease += "</Disease>";
            this.allSymptom = new List<symptomEntity>(proc.getUniqueSymptom(xmlListDisease, listSymptom));
        }
        public void UpdateListRank(int symptomid)
        {
            foreach(disease diseaseobj in this.listDisease){
                foreach(Symptom symobj in diseaseobj.symptom.ToList()){
                    if(symobj.id == symptomid){
                        System.Diagnostics.Debug.WriteLine("val + " + symobj.val);
                        diseaseobj.currentWeight += symobj.val;
                        try
                        {
                            diseaseobj.symptom.Remove(symobj);
                        }
                        catch(Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("Unsubscribe Error " + e.Message);
                        }
                    }
                }
            }
        }
        //sum weight of all symptom which appear in FB to current weight
    }
}